<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" template="/home.xhtml">
	<ui:define name="corpo">
		<h:form prependId="false">
			<p:panel header="Administrar Medicamentos" style="background: #dbfbda;font-size:15px;min-height:700px;margin-top:10px;float:left;width:99%">
				<h:panelGroup style="float: left;width:250px;" layout="block">
					<ui:include src="menu.xhtml" />
				</h:panelGroup>
				<h:panelGroup layout="block" style="float:left">
				    	<p:dataTable var="medicamento" value="#{manterAdministradorBean.administradorForm.medicamentos}" id="table_medicamento" paginator="true" rows="15"  
				                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
				                 paginatorPosition="bottom" style="width:700px">  
					  
				            <f:facet name="header">
				                <h:outputText value="Medicamentos Cadastrados" />
				            </f:facet>  
					        <p:column>  
					            <f:facet name="header">
					                <h:outputText value="Medicamento" />  
					            </f:facet>
					            <h:outputText value="#{medicamento.medicamento}" />  
					        </p:column>  

					        <p:column>  
					            <f:facet name="header">
					                <h:outputText value="Genérico" />  
					            </f:facet>  
					            <h:outputText value="#{medicamento.generico}" />  
					        </p:column>  

					        <p:column>  
					            <f:facet name="header">
					                <h:outputText value="Laboratório" />  
					            </f:facet>  
					            <h:outputText value="#{medicamento.laboratorio}" />  
					        </p:column>  
					  
					        <p:column style="text-align: center">  
					            <f:facet name="header">
					                <h:outputText value="Excluir" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-trash" oncomplete="excluir.show()">
					            	<f:setPropertyActionListener target="#{manterMedicamentoBean.medicamento}" value="#{medicamento}" />
					            </p:commandButton>  
					        </p:column>  
	
					        <p:column style="text-align: center">  
					            <f:facet name="header">
					                <h:outputText value="Editar" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-transferthick-e-w" oncomplete="editar.show()" update="pnl_edit">
					            	<f:setPropertyActionListener target="#{manterMedicamentoBean.medicamento}" value="#{medicamento}" />					            	
					            </p:commandButton>
					        </p:column>  
					  
					  		<f:facet name="footer">
				                <p:commandButton value="Cadastrar" image="ui-icon ui-icon-circle-plus" style="position: relative; right: 290px;" oncomplete="cadastrar.show()" action="#{manterMedicamentoBean.limparCampo}" update="pnl_cadastro" />
				            </f:facet>
					    </p:dataTable>
				</h:panelGroup>
			 
			</p:panel>
			
		</h:form>
		
		<ui:include src="modal_excluir_admin.xhtml">
			<ui:param name="bean" value="#{manterMedicamentoBean}" />
			<ui:param name="metodo" value="excluir" />
			<ui:param name="idTabela" value="table_medicamento" />
		</ui:include>
		
		<p:dialog header="Editar" widgetVar="editar" resizable="false" modal="true" width="500" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				<h:panelGrid columns="2" cellspacing="0" cellpadding="2" id="pnl_edit">
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.nome']}" style="font-weight:bold" for="medicamento" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>						
					<p:inputText value="#{manterMedicamentoBean.medicamento.medicamento}" size="25" maxlength="100" label="medicamento" required="true" id="medicamento" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="medicamento" id="msgMedicamento" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.generico']}" style="font-weight:bold" for="generico" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.generico}" size="25" maxlength="50" label="generico" required="true" id="generico" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="generico" id="msgGenerico" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.contraIndicacao']}" for="contraIndicacao" style="font-weight:bold" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.contraindicacao}" size="46" maxlength="50" label="contra-indicacao" required="true" id="contraIndicacao" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="contraIndicacao" id="msgContraIndicacao" styleClass="msg_erro_required"/>

					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.laboratorio']}" style="font-weight:bold" for="laboratorio" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.laboratorio}" size="46" maxlength="100" label="laboratorio" required="true" id="laboratorio" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />	
					<h:outputText />
					<h:message for="laboratorio" id="msgLaboratorio" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.posologia']}" style="font-weight:bold" for="posologia" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputTextarea value="#{manterMedicamentoBean.medicamento.posologia}" maxlength="300" label="posologia" required="true" id="posologia" maxHeight="80" style="border: solid 1px #5FA03F;background-color: #FFF; width: 300px; height: 80px"  styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="posologia" id="msgPosologia" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.substancia']}" style="font-weight:bold" for="substancia" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputTextarea value="#{manterMedicamentoBean.medicamento.substancia}" maxlength="300" label="substancia" required="true" id="substancia" maxHeight="80" style="border: solid 1px #5FA03F;background-color: #FFF; width: 300px; height: 80px" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="substancia" id="msgSubstancia" styleClass="msg_erro_required"/>
					
				</h:panelGrid>
				
				<h:panelGroup style="padding-top: 20px;padding-bottom:10px;text-align:center" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterMedicamentoBean.editar}" oncomplete="validaEdicao();" update="pnl_edit, table_medicamento, func_javascript"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" oncomplete="editar.hide()"/>
				</h:panelGroup>
			</h:form>
	    </p:dialog>
	    
		<p:dialog header="Cadastrar" widgetVar="cadastrar" resizable="false" modal="true" width="500" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				<h:panelGrid columns="2" cellspacing="0" cellpadding="2" id="pnl_cadastro">
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.nome']}" style="font-weight:bold" for="medicamentoCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.medicamento}" size="25" maxlength="100" label="medicamento" required="true" id="medicamentoCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="medicamentoCad" id="msgMedicamentoCad" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.generico']}" style="font-weight:bold" for="genericoCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.generico}" size="25" maxlength="50" label="generico" required="true" id="genericoCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="genericoCad" id="msgGenericoCad" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.contraIndicacao']}" style="font-weight:bold" for="contraIndicacaoCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterMedicamentoBean.medicamento.contraindicacao}" size="46" maxlength="50" label="contra-indicacao" required="true" id="contraIndicacaoCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="contraIndicacaoCad" id="msgContraIndicacaoCad" styleClass="msg_erro_required"/>
						
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.laboratorio']}" style="font-weight:bold" for="laboratorioCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>						
					<p:inputText value="#{manterMedicamentoBean.medicamento.laboratorio}" size="46" maxlength="100" label="laboratorio" required="true" id="laboratorioCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="laboratorioCad" id="msgLaboratorioCad" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.posologia']}" style="font-weight:bold" for="posologiaCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputTextarea value="#{manterMedicamentoBean.medicamento.posologia}" maxlength="300" label="posologia" required="true" id="posologiaCad" style="border: solid 1px #5FA03F;background-color: #FFF; width: 300px; height: 80px" maxHeight="80" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="posologiaCad" id="msgPosologiaCad" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<span class="campoObrigatorio">*</span>
						<h:outputLabel value="#{msg['display.label.medicamento.substancia']}" style="font-weight:bold" for="substanciaCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputTextarea value="#{manterMedicamentoBean.medicamento.substancia}" maxlength="300" label="substancia" maxHeight="80" required="true" id="substanciaCad" style="border: solid 1px #5FA03F;background-color: #FFF; width: 300px; height: 80px"  styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="substanciaCad" id="msgSubstanciaCad" styleClass="msg_erro_required"/>
				
				</h:panelGrid>
				<h:panelGroup style="padding-top: 20px;padding-bottom:10px;text-align:center" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterMedicamentoBean.cadastrar}" oncomplete="validaCadastro();" update="pnl_cadastro,table_medicamento,func_javascript"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" onclick="cadastrar.hide()"/>
				</h:panelGroup>
				
				<p:outputPanel id="func_javascript">
					<script type="text/javascript">
	
						function validaCadastro(){
							if(#{!empty requestScope.cadastrado}){
								cadastrar.hide();
							}
						}
										
						function validaEdicao(){
							if(#{!empty requestScope.editado}){
								editar.hide();
							}
						}						
								
					</script>
				</p:outputPanel>
				
			</h:form>
	    </p:dialog>
		
	</ui:define>
</ui:composition>